import React, { Component } from 'react';


import FormInput from '../../core/components/form.input';
import Header from '../../core/components/header';
import Dialog from '../../core/utils/dialog'
import { Post } from '../../core/utils/fetch';

class UserPassword extends Component {

    state = {
        passwordData: {},
    };

    render() {
        let { passwordData } = this.state;
        return (
            <div>
                <Header title="系统管理" subTitle="System Manage"></Header>

                <div className="row">
                    <div className="col-lg-4">
                        <h2>密码修改</h2>

                        <form role="form">
                            <FormInput className="has-success" type="password" label="旧密码" name="oldPwd" dataItem={passwordData}></FormInput>
                            <FormInput className="has-warning" type="password" label="新密码" name="newPwd" dataItem={passwordData}></FormInput>
                            <FormInput className="has-error" type="password" label="再次输入密码" name="newPwdConfirm" dataItem={passwordData}></FormInput>

                            <button type="button" className="btn btn-success btn-modify" onClick={this._onSave}>保存</button>
                        </form>

                    </div>
                </div>
            </div>
        );
    }

    _onSave = () => {
        let p = this.state.passwordData;
        if (p.newPwd !== p.newPwdConfirm) {
            Dialog.alert('两次输入密码不一致');
        } else {
            Post(`/spi/user/change/pwd?oldPwd=${p.oldPwd}&newPwd=${p.newPwd}`, {})
                .then(() => {
                    Dialog.alert('修改密码成功');
                });
        }
    };
}

export default UserPassword;